<?php
// Hoook into the 'wp_dashboard_setup' action to register our function
function remove_dashboard_widgets() {
	// Globalize the metaboxes array, this holds all the widgets for wp-admin
	global $wp_meta_boxes;
	
	// Main column:
	//unset($wp_meta_boxes['dashboard']['normal']['high']['dashboard_browser_nag']);
	//unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
	
	// Side Column:
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']); //WordPress Blog 
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']); //Other WordPress News 
} 
add_action('wp_dashboard_setup', 'remove_dashboard_widgets' );

# Refer http://ijotted.blogspot.com/2012/05/sql-queries-to-delete-wordpress-post.html
// Disable auto save(Tranh phinh database)
add_action( 'admin_init', 'disable_autosave' );
function disable_autosave() {
	wp_deregister_script( 'autosave' );
}

// Begin page control, co the tuy bien sao cho phu hop voi ngu canh
// Khong cho phep xoa page hoac post
function restrict_post_deletion($post_ID){
	//$user = get_current_user_id();
	//$restricted_users = array(21,25,54,2,19);
	global $restricted_pages;
	//if(in_array($user, $restricted_users) && in_array($post_ID, $restricted_pages)){
	if( in_array($post_ID, $restricted_pages) ){
		echo "You are not authorized to delete this page.";
		exit;
	}
}
//add_action('wp_trash_post', 'restrict_post_deletion', 10, 1);
add_action('before_delete_post', 'restrict_post_deletion', 10, 1);

/*
add_filter( 'parse_query', 'exclude_pages_from_admin' );
function exclude_pages_from_admin($query) {
	global $pagenow, $post_type, $restricted_pages;
	if (is_admin() && $pagenow == 'edit.php' && $post_type =='page') {
		$query->query_vars['post__not_in'] = $restricted_pages;
	}
} 
//add_action('load-edit.php', 'exclude_pages_from_admin');
//or use the following way */
function exclude_pages_from_admin() {
	if ($_GET['post_type'] !== 'page') return;
	add_filter('posts_where', 'my_posts_where_filter');
}
function my_posts_where_filter($sql) {
	global $wpdb, $restricted_pages;
	$sql = " AND $wpdb->posts.ID NOT IN (". implode(',', $restricted_pages) .")" . $sql;
	return $sql;
}
// End page control

//Them or Bo Thuoc Tinh Appearance
//add_action( 'admin_init', 'the_wp_menu' );

function the_wp_menu()
{
	//remove_submenu_page( 'index.php','update-core.php' );
	//remove_submenu_page( 'index.php','index.php' );
	remove_submenu_page( 'themes.php','theme-editor.php' );
	remove_submenu_page( 'themes.php','themes.php' );
}
/*
// Begin bo qua update and themes
//bo qua update core
add_filter( 'pre_site_transient_update_core', create_function( '$a', "return null;" ) );
//bo qua update plugins
add_filter( 'pre_site_transient_update_plugins', create_function( '$a', "return null;" ) );
// End
*/

/* // remove menu Hide and show thuoc tinh menu left of Wordpress
add_action( 'admin_menu', 'my_remove_menu_pages' );
function my_remove_menu_pages() {
	remove_menu_page('link-manager.php');
	remove_menu_page('tools.php'); 
} or use the following way */
function remove_menus () {
	global $menu;
	//$restricted = array(__('Dashboard'), __('Posts'), __('Media'), __('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Users'), __('Settings'), __('Comments'), __('Plugins'));
	$restricted = array(__('Links'), __('Tools'), __('Comments'));
	end ($menu);
	while (prev($menu)){
		$value = explode(' ',$menu[key($menu)][0]);
		if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
	}
}
add_action('admin_menu', 'remove_menus');
//End Remove Menu
?>